import java.awt.Color;
import java.awt.Graphics2D;
import java.util.*;
//the super class for all tetris pieces. Each piece contains an array list of blocks that make up the piece
public abstract class Piece {
	protected ArrayList<Block> blocks;
	protected Grid gr;
	protected Color color;
	public boolean freeze=false;
	String name="";
	TetrisGame game;
	
	public Piece(Grid gr, TetrisGame game){
		this.gr=gr;
		blocks=new ArrayList<Block>();
		this.game=game;
	}
	
	public abstract void fillBlocks();
	
	public void freeze(){
		freeze=true;
	}
	
	public void putSelfInGrid(Graphics2D g){
		for(int i=0;i<blocks.size();i++){
			Block b=blocks.get(i);
			b.putSelfInGrid(gr,g);
		}
	}
	public ArrayList<Block> getBlocks(){
		return blocks;
	}
	
	public Location getLoc(){
		Location loc=blocks.get(0).getLoc();
		for(Block b:blocks){
			if (b.getLoc().getCol()<loc.getCol()&&b.getLoc().getRow()<loc.getRow()){
				loc=b.getLoc();
			}
		}
		return loc;
	}
	
	public void move(){
		if(!freeze){
			for(int i=0;i<blocks.size();i++){
				Block b=blocks.get(i);
				b.setLoc(b.getLoc().getLocationUnder());
				b.setCoords();
			}
		}
	}
			
	
	public String toString(){
		String string="";
		for(int i=0;i<blocks.size();i++){
			Block b=blocks.get(i);
			string+=b.getLoc()+", ";
		}
		return name+": "+string;
	}
}
